package com.iqiju.id.server.controller;

import com.iqiju.id.server.service.IdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class IdController {

    @Autowired
    private IdService idService;

    @GetMapping("id")
    public Map id(){
        try {
            long id = idService.nextId();
            Map map = new HashMap(8);
            map.put("content",String.valueOf(id));
            map.put("state",0);
            map.put("message","SUCCESS");
            return map;
        } catch (Throwable e) {
            log.error("获取id异常======================================error");
            log.error(e.getMessage(), e);
            Map map = new HashMap(4);
            map.put("state",500);
            map.put("message","ERROR");
            return map;
        }
    }

}
